package org.swfer.UIC 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 * 复选框容器
	 * 可选部件 item0,item1,~~~
	 * 回调事件 change
	 * @author swfer
	 */
	public class CheckBoxGroup extends ButtonGroup 
	{
		public static const CHNAGE:String = 'change';
		protected var _selectIndexs:Array;
		
		public function CheckBoxGroup(view:MovieClip) 
		{
			super(view);
		}
		
		override protected function init():void
		{
			itemDef = ChexBox;
			super.init();
		}
		
		override protected function onItemClick(e:MouseEvent):void 
		{
			var index:int = buttonViews.indexOf(e.currentTarget);
			_selectIndexs = _selectIndexs || [];
			
			if (buttons[index].selected)
			{
				if (_selectIndexs.indexOf(index) == -1)
				{
					_selectIndexs.push(index);
				}
			}
			else
			{
				_selectIndexs.splice(index, 1);
			}
			
			executeCallBack(CHNAGE);
		}
		
		public function get selectIndexs():Array { return _selectIndexs;}
		public function set selectIndexs(value:Array):void 
		{
			_selectIndexs = value;
			
			for each (var i:uint in value) 
			{
				buttons[i].selected = true;
			}
			
			executeCallBack(CHNAGE);
		}
		
	}

}